const grpc = require('@grpc/grpc-js');
const { ChannelCredentials, Client, Metadata }  = grpc;

const client = new Client(
    `localhost:5004`,
    ChannelCredentials.createInsecure()
);



function unary(input) {

    return new Promise((resolve, reject) => {
        const gCall = client.makeUnaryRequest(
            `/communicator_objects.UnityToExternalProto/Exchange`,
            () => Buffer.from(input),
            (value) => value,
            {},
            new Metadata(),
            (err, value) => {
                resolve(new Uint8Array(value));
            }
        )

        gCall.addListener('metadata', (metadata) => {
            console.log(metadata);
        });

        gCall.addListener('status', (status) => {
            console.log(status);
        });
    });


}


unary(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])).then((value) => {
    console.log(value);
});